package com.mchsdk.paysdk.bean;


import android.content.Context;
import android.os.Handler;
import android.os.Message;
import android.text.TextUtils;

import com.mchsdk.open.ChangePlayerLevelCallback;
import com.mchsdk.paysdk.bean.PersonalCenterModel;
import com.mchsdk.paysdk.common.Constant;
import com.mchsdk.paysdk.http.process.ChangePlayerLevelProcess;
import com.mchsdk.paysdk.utils.MCLog;
import com.mchsdk.paysdk.utils.ToastUtil;

public class ChangePlayerLevel {

    public static final String TAG = "ChangePlayerLevel";
    String type;
    String role_level;
    ChangePlayerLevelCallback plca;
    private Handler mHandler = new Handler() {

        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            switch (msg.what) {
                case Constant.Change_Role_Level_SUCCESS:// 登陆成功
                    if (getPlca()!=null) {
                        getPlca().callback("1");
                    }
                    break;
                case Constant.Change_Role_Level_FAIL:// 登陆失败
                    if (getPlca()!=null) {
                        getPlca().callback("0");
                    }
                    break;
            }
        }
    };
    public ChangePlayerLevel(String type, String role_level, ChangePlayerLevelCallback plca) {

        if (type!=null){
            this.type = type;
        }else {
            MCLog.w(TAG,"#type is null");
        }

        this.role_level = role_level;
        this.plca = plca;
    }

    /**
     * 配置更改玩家等级需要的参数,发起请求
     */
    public void change(){
        if (null == PersonalCenterModel.getInstance().channelAndGame
                || TextUtils
                .isEmpty(PersonalCenterModel.getInstance().channelAndGame
                        .getAccount())) {
            MCLog.w(TAG,"请登录");
            return;
        }
            MCLog.w(TAG,"#type"+type);
            ChangePlayerLevelProcess process = new ChangePlayerLevelProcess();
            process.setRole_level(role_level);
            process.setType(2);
            process.post(mHandler);

    }

    public ChangePlayerLevelCallback getPlca() {
        if (plca!=null){
            return plca;
        }else {
            return null;
        }

    }
}
